package com.dq.domain.setup;

import com.dq.vo.baseVo.VO;
import com.dq.domain.base.BaseEntity;

import com.dq.domain.position.OrgPosition;
import com.dq.domain.sys.section.SysSection;
import com.dq.utils.TimeUtil;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import javax.persistence.Entity;
import javax.persistence.ManyToOne;
import java.math.BigDecimal;

/**
 * @Author luchangtong
 * @Date 2019/11/20 15:29
 */
@Entity
@Data
@ApiModel("业务提成设置")
public class WorkRoyaltySet extends BaseEntity implements VO.ToVO {
    @ApiModelProperty("编号")
    protected String royaltyNo;

    @ApiModelProperty(value = "组织部门/门店",hidden = true)
    @ManyToOne
    protected SysSection org;
    @ApiModelProperty(value = "岗位",hidden = true)
    @ManyToOne
    protected OrgPosition orgPosition;
    @ApiModelProperty("阶梯上限")
    protected BigDecimal topLimitPrice;
    @ApiModelProperty("阶梯下限")
    protected BigDecimal lowerLimitPrice;
    @ApiModelProperty("计算比例")
    protected BigDecimal proportion;


    @Data
    @ApiModel(value = "业务提成设置视图")
    public static class Vo implements VO {
        @ApiModelProperty("业务提成id")
        protected Long id;
        @ApiModelProperty("编号")
        protected String royaltyNo;
        @ApiModelProperty("提成上线")
        protected BigDecimal topLimitPrice;
        @ApiModelProperty("提成下限")
        protected BigDecimal lowerLimitPrice;
        @ApiModelProperty("计算比例")
        protected BigDecimal proportion;
        @ApiModelProperty("岗位")
        protected String orgPositionName;
        protected Long orgPositionId;
        protected String orgName;
        protected Long orgId;
        @ApiModelProperty(value = "创建时间")
        private String createTime;
        @ApiModelProperty(value = "修改时间")
        private String lastModifyTime;
        @ApiModelProperty(value = "创建者id")
        private Long createUserId;
        @ApiModelProperty(value = "创建者name")
        private String createUserName;
        @ApiModelProperty(value = "修改者id")
        private Long updateUserId;
        @ApiModelProperty(value = "修改者name")
        private String updateUserName;
    }

    @Data
    @ApiModel("业务提成列表视图")
    public static class RoyaltListVo{
        @ApiModelProperty("业务提成id")
        protected Long id;
        @ApiModelProperty("提成上线")
        protected BigDecimal topLimitPrice;
        @ApiModelProperty("提成下限")
        protected BigDecimal lowerLimitPrice;
        @ApiModelProperty("计算比例")
        protected BigDecimal proportion;
        @ApiModelProperty("岗位id")
        protected Long orgPositionId;
        @ApiModelProperty("岗位")
        protected String orgPosition;

    }

    public RoyaltListVo toRoyaltListVo(){
        WorkRoyaltySet.RoyaltListVo royaltListVo = new WorkRoyaltySet.RoyaltListVo();
        royaltListVo.id = this.getId();
        royaltListVo.topLimitPrice =fmt(this.getTopLimitPrice());
        royaltListVo.lowerLimitPrice = fmt(this.getLowerLimitPrice());
        royaltListVo.proportion = fmt(this.getProportion());
        royaltListVo.orgPositionId = fmt(this.getOrgPosition().getId());
        royaltListVo.orgPosition  = fmt(this.getOrgPosition().getPostName());
        return royaltListVo;
    }

    @Override
    public VO toVO(boolean isRecursion) {
        Vo vo = new Vo();
        vo.id = this.getId();
        vo.royaltyNo = fmt(this.getRoyaltyNo());
        vo.topLimitPrice =fmt(this.getTopLimitPrice());
        vo.lowerLimitPrice = fmt(this.getLowerLimitPrice());
        vo.proportion = fmt(this.getProportion());
        vo.orgPositionName  =this.getOrgPosition()!= null ? fmt(this.getOrgPosition().getPostName()):"";
        vo.orgPositionId =this.getOrgPosition()!= null ? fmt(this.getOrgPosition().getId()):null;
        vo.orgId = fmt(this.getOrg().getId());
        vo.orgName = fmt(this.getOrg().getSimpleName());
        vo.createTime = TimeUtil.longToString(this.createTime, TimeUtil.YYYY_MM_DD_HH_MM_SS);
        vo.lastModifyTime = TimeUtil.longToString(this.lastModifyTime, TimeUtil.YYYY_MM_DD_HH_MM_SS);
        vo.createUserId = this.createUser == null ? null : this.createUser.getId();
        vo.createUserName = this.createUser == null ? null : this.createUser.getUsername();
        vo.updateUserId = this.updateUser == null ? null : this.updateUser.getId();
        vo.updateUserName = this.updateUser == null ? null : this.updateUser.getUsername();
        return vo;
    }
}
